<template>
	<view class="fond-good-box flex f-d-c">
		<view class="form-item flex a-i-c j-c-b">
			<view class="left color-333 f-s-24">
				招聘内容
			</view>
			<view class="right">
				<view class="box1 w-100 flex a-i-c j-c-b">
					<input class="f-s-24 input" type="text" v-model="name" placeholder="请输入招聘内容" placeholder-class="color-999"/>
				</view>
			</view> 
		</view>
		<picker mode="selector" :range="send_car_mode" range-key="name" @change="changeCarModel">
		<view class="form-item flex a-i-c j-c-b">
			<view class="left color-333 f-s-24">
				车型名称
			</view>
			<view class="right">
				<view class="box1 w-100 flex a-i-c j-c-b">
					<input class="f-s-24 input" type="text" :disabled="true" v-model="car_name" placeholder="请选择车型" placeholder-class="color-999"/>
				</view>
			</view>
		</view>
		</picker>
		<view class="form-item flex a-i-c j-c-b">
			<view class="left color-333 f-s-24">
				驾龄要求
			</view>
			<view class="right">
				<view class="box1 w-100 flex a-i-c j-c-b">
					<input class="f-s-24 input" type="digit" v-model="age" placeholder="请输入您的驾龄要求" placeholder-class="color-999"/>
				</view>
			</view> 
		</view>
		<view class="form-item flex a-i-c j-c-b" @click="getChooseLocation">
			<view class="left color-333 f-s-24">
				工作地点
			</view>
			<view class="right">
				<view class="box1 w-100 flex a-i-c j-c-b">
					<input class="f-s-24 input" type="text" :disabled="true" v-model="work_address_desc" placeholder="请输入工作地点 具体到区" placeholder-class="color-999"/>
				</view>
			</view> 
		</view>
		<view class="form-item flex a-i-c j-c-b">
			<view class="left color-333 f-s-24">
				最低薪资
			</view>
			<view class="right">
				<view class="box1 w-100 flex a-i-c j-c-b">
					<input class="f-s-24 input" type="digit" v-model="first_salary" placeholder="请输入薪资范围" placeholder-class="color-999"/>
				</view>
			</view> 
		</view>
		<view class="form-item flex a-i-c j-c-b">
			<view class="left color-333 f-s-24">
				最高薪资
			</view>
			<view class="right">
				<view class="box1 w-100 flex a-i-c j-c-b">
					<input class="f-s-24 input" type="digit" v-model="last_salary" placeholder="请输入薪资范围" placeholder-class="color-999"/>
				</view>
			</view> 
		</view>
		<view class="form-item flex a-i-c j-c-b">
			<view class="left color-333 f-s-24">
				联系电话
			</view>
			<view class="right">
				<view class="box1 w-100 flex a-i-c j-c-b">
					<input class="f-s-24 input" type="number" v-model="mobile" placeholder="请输入您的联系电话" placeholder-class="color-999"/>
				</view>
			</view>
		</view>
		<view class="form-item flex j-c-b m-b-30">
			<view class="left color-333 f-s-24">
				工作内容
			</view>
			<view class="right">
				<view class="box1 w-100 flex a-i-c j-c-b">
					<textarea name="" class="textarea-box f-s-26 color-333" v-model="content"></textarea>
				</view>
			</view>
		</view>
		<bottom-btn :positon="true" @click="requestData">确认发布</bottom-btn>
	</view>
</template>

<script>
	import uploadBox from "@/components/myComponents/uploadBox.vue"
	import bottomBtn from "@/components/myComponents/bottomBtn.vue"
	import {reditTo} from "@/nav.js"
	export default {
		name:"findGood",
		components:{
			"upload-box":uploadBox,
			"bottom-btn":bottomBtn
		},
		data() {
			return {
				car_name:"",
				name:"",
				mobile:"",
				age:"",
				work_address_desc:"",
				marks:"",
				first_salary:"",
				last_salary:"",
				content:"",
				model:[],
				send_car_mode:[],
				lng:'',
				lat:'',
				work_lng:"",
				work_lat:"",
				is_post:"",
				id:""
			};
		},
		mounted() {
			this.send_car_mode = this.$store.state.send_car_mode
			this.getLocationThis()
			this.setPageData()
		},
		methods:{
			setPageData(){
				let str = this.$store.state.page_tab_info
				let item = {}
				if(!!str){
					item = JSON.parse(str)
					Object.keys(item).map(val=>{
						if(val!=='model'){
							this[val] = item[val]
						}
					})
					for(let key in item.model){
						this.car_name += item.model[key]+','
						this.model.push(key)
					}
				}
			},
			getLocationThis(){
				let that = this
				uni.showLoading({
					title:"定位中..."
				})
				that.$location.myGetLocation((res)=>{
					uni.hideLoading()
					that.lng = res.lng
					that.lat = res.lat
				},false)
			},
			getChooseLocation(type){
				let that = this
				that.$location.myGetLocation(res=>{
					console.log(res)
					that.work_lng = res.longitude
					that.work_lat = res.latitude
					that.work_address_desc = res.address
				})
			},
			requestData(){
				if(this.name === ""){
					uni.showToast({
						title:"请输入招聘内容",
						icon:"none"
					})
					return
				}
				if(this.car_name === ""){
					uni.showToast({
						title:"请选择车型",
						icon:"none"
					})
					return
				}
				if(this.mobile === ""){
					uni.showToast({
						title:"请输入手机号码",
						icon:"none"
					})
					return
				}
				if(this.work_address_desc === ""){
					uni.showToast({
						title:"请输入工作地点",
						icon:"none"
					})
					return
				}
				if(this.age === ""){
					uni.showToast({
						title:"请输入车龄",
						icon:"none"
					})
					return
				}
				if(this.first_salary === "" || this.last_salary === ''){
					uni.showToast({
						title:"请输入薪资范围",
						icon:"none"
					})
					return
				}
				if(this.content.length<=0){
					uni.showToast({
						title:"请输入工作内容",
						icon:"none"
					})
					return
				}
				this.postSellingCar()
			},
			getLocationThis(){
				let that = this
				uni.showLoading({
					title:"定位中..."
				})
				that.$location.myGetLocation((res)=>{
					uni.hideLoading()
					that.lng = res.lng
					that.lat = res.lat
				},false)
			},
			postSellingCar(){
				let that = this
				// return
				if(that.is_post !== ''){
					return
				}
				uni.showLoading({
					title:"提交中..."
				})
				that.is_post = '1'
				that.util.postRequest({
					url:"v1/content/work_edit",
					data:{
						type:0,
						name:that.name,
						mobile:that.mobile,
						age:that.age,
						sex:"",
						first_salary:that.first_salary,
						model:that.model,
						last_salary:that.last_salary,
						work_lat:that.work_lat,
						content:that.content,
						work_lng:that.work_lng,
						images:[],
						lng:that.lng,
						lat:that.lat,
						id:that.id
					}
				}).then(res=>{
					uni.hideLoading()
					console.log(res)
					that.is_post=""
					// reditTo({url:'/pages/success/successPage'})
					uni.showToast({
						title:"待审核",
						duration:2500
					})
					// let timeout = setTimeout(()=>{
					// 	clearTimeout(timeout)
					// 	uni.navigateBack()
					// },2500)
				}).catch(e=>{
					uni.hideLoading()
				})
			},
			changeCarModel(e){
				console.log(e)
				let index = e.detail.value
				this.model[0]=this.send_car_mode[index].id
				this.car_name = this.send_car_mode[index].name
			}
		}
	}
</script>

<style lang="scss" scoped>
	.textarea-box{
		width: 100%;
		height: 158upx;
		background: #F7F7F7;
		border-radius: 8upx;
		padding: 20upx;
	}
	.fond-good-box{
		width: 100%;
		border-radius: 20upx;
		background-color: #FFFFFF;
		padding: 30upx;
		.upload-form{}
		.form-item{
			width: 100%;
			padding: 0 16upx;
			min-height: 80upx;
			.right{
				width: 430upx;
				.box1{
					.input{
						width: 380upx;
					}
				}
				.box2{
					.title{
						margin-bottom: 26upx;
						line-height: 50upx;
					}
				}
			}
			.left{
				line-height: 50upx;
			}
		}
	}
	.form-next-icon{
		width: 26upx;
		height: 26upx;
	}
	
</style>